package com.findmeastore.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.findmeastore.bo.ProductBo;
import com.findmeastore.dao.IProductDAO;

public class ProductDAOImpl implements IProductDAO{
	private HibernateTemplate hibernateTemplate;
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	public Integer getTotalProductCount(){
		return DataAccessUtils.intResult(hibernateTemplate.find("select count(*) from ProductBo"));
	}
	@SuppressWarnings("unchecked")
	public List<ProductBo> getAllProducts() {
		return hibernateTemplate.find("from ProductBo");
	}

	public ProductBo getProductById(Integer id) {
		return (ProductBo)hibernateTemplate.get(ProductBo.class, id);
	}
	
	public void saveProduct(ProductBo productBo) {
		hibernateTemplate.save(productBo);
	}
	
}
